package com.gaofeng.day07;

import java.util.*;

public class demo5 {
    public static void main(String[] args) {
        //
        String[] arr = {"A","B","C","D"};

        //创建一个集合
        ArrayList<String> lists = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            int index = random.nextInt(arr.length);

            lists.add(arr[index]);
        }

        System.out.println(lists);

        HashMap<String, Integer> hm = new HashMap<>();

        int count = 0;
        for (String item : lists) {
            if(hm.containsKey(item)){
                hm.put(item,++count);
            }else{
                hm.put(item,1);
            }
        }

        System.out.println(hm);

        Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        int max = 0;
        for (Map.Entry<String, Integer> entry : entries) {
            if(entry.getValue() > max){
                max = entry.getValue();
            }
        }

        System.out.println(max);

        String name = "";
        for (Map.Entry<String, Integer> entry : entries) {

            if(entry.getValue() == max){

                name = entry.getKey();
            }
        }
        System.out.println(name);

    }
}
